<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // JSON对象 字符串 --->  JS对象
    /*
    值的类型
    1 数值
    2 字符串
    3 布尔值
    4 JSON数组
    5 JSON对象
    6 null
    */
    var s = `{
      "id":1001,
      "name":"张三",
      "age": 20,
      "sex": "男",
      "marrided":false,
      "son":{
        "id":10001,
        "name":"李四",
        "age": 10,
        "sex": "男",
        "marrided":false
      },
      "hobby":["睡觉","玩游戏","刷视频"]
    }`

    console.log(s);

    var p = JSON.parse(s);// JSON对象字符串  解析为  JS对象
    console.log(p);

    for (k in p) {
      console.log(p[k]);
      if (Array.isArray(p[k])) {
        p[k].forEach(ele => {
          console.log(ele);
        });
      }
    }

  </script>
</body>

</html>